<?php
namespace app\controller\handler;
use app\controller\Common;
use think\Db;
use think\Model;

class Upload extends Common{

  public function uploadImage(){
    if(!empty($_FILES)){
      $d = explode('-', date("Y-y-m-d-H-i-s"));
      $filepath = $d[0].$d[2].$d[3];
      $fileParts = pathinfo($_FILES['file']['name']);
      $file_name = $_FILES['file']['name'];
      $tmp_name = $_FILES['file']['tmp_name'];
      $path = PROJECT_PATH.'/upload/image/'.$filepath.'/';
      if(!is_dir($path)){
        mkdir($path,0777,true);
      }
      $target = $path.time().$file_name;
      if (move_uploaded_file($tmp_name,$target)){
        $result['ret'] = 1;
        $result['msg'] = '上传成功';
        $result['url'] = '/upload/image/'.$filepath.'/'.time().$file_name;
      }else{
        $result['ret'] = 0;
        $result['msg'] = '上传失败';
      }
    }else{
      $result['ret'] = 0;
      $result['msg'] = '上传失败，缺少文件信息';
    }
    return $result;
  }




}//END